package cn.lg.soar.system.biz.modules.auth.model;

import cn.lg.soar.system.api.model.UserPostItemVO;
import cn.lg.soar.system.biz.modules.auth.entity.AccountBind;
import cn.lg.soar.system.biz.modules.auth.entity.Role;
import cn.lg.soar.system.biz.modules.auth.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class UserDetailVo extends User {

    private static final long serialVersionUID = 6850908496978491051L;

    @Schema(description = "岗位")
    private List<UserPostItemVO> posts;

    @Schema(description = "账号")
    private List<AccountBind> accountBinds;

    @Schema(description = "来自用户的角色")
    private List<Role> userRoles;

    @Schema(description = "来自岗位的角色")
    private List<Role> postRoles;

    public UserDetailVo() {
    }

    public UserDetailVo(User source) {
        this.setId(source.getId());
        this.setUsername(source.getUsername());
        this.setNickname(source.getNickname());
        this.setAvatar(source.getAvatar());
        this.setPwdErrorCount(source.getPwdErrorCount());
        this.setLastLoginDate(source.getLastLoginDate());
        this.setLoginCount(source.getLoginCount());
        this.setCurrentTenantId(source.getCurrentTenantId());
        this.setUserType(source.getUserType());
        this.setStatus(source.getStatus());
        this.setPassword(source.getPassword());
        this.setSecret(source.getSecret());
        this.setDeleted(source.getDeleted());
        this.setVersion(source.getVersion());
        this.setCreateTime(source.getCreateTime());
        this.setCreateBy(source.getCreateBy());
        this.setUpdateTime(source.getUpdateTime());
        this.setUpdateBy(source.getUpdateBy());
    }

    public User toUser(){
        User target = new User();

        target.setId(this.getId());
        target.setUsername(this.getUsername());
        target.setNickname(this.getNickname());
        target.setAvatar(this.getAvatar());
        target.setPwdErrorCount(this.getPwdErrorCount());
        target.setLastLoginDate(this.getLastLoginDate());
        target.setLoginCount(this.getLoginCount());
        target.setCurrentTenantId(this.getCurrentTenantId());
        target.setUserType(this.getUserType());
        target.setStatus(this.getStatus());
        target.setPassword(this.getPassword());
        target.setSecret(this.getSecret());
        target.setDeleted(this.getDeleted());
        target.setVersion(this.getVersion());
        target.setCreateTime(this.getCreateTime());
        target.setCreateBy(this.getCreateBy());
        target.setUpdateTime(this.getUpdateTime());
        target.setUpdateBy(this.getUpdateBy());
        return target;
    }
}
